<template>
  <div class="table-box">
    <div class="operation-box">
      <div class="input-box">
        任务编号：
        <el-input
          v-model="search"
          placeholder="请输入关键字"
          class="input__item"
        />
        <el-button type="danger">查询</el-button>
      </div>

      <div class="add-box">
        <el-button type="primary" @click="dialogVisible = true">
          <el-icon><CirclePlus /></el-icon>
          制定巡检任务
        </el-button>
      </div>
    </div>

    <el-table
      :data="tableData"
      stripe
      border
      table-layout="auto"
      style="max-width: 100vw; min-width: 1000px"
    >
      <el-table-column prop="id" label="任务编号" />
      <el-table-column prop="task" label="任务名称" />
      <el-table-column prop="route" label="巡检线路" />
      <el-table-column prop="start" label="起始杆号" />
      <el-table-column prop="end" label="终止杆号" />
      <el-table-column prop="name" label="下发人" />
      <el-table-column prop="time" label="下发时间" />
      <el-table-column prop="state" label="任务状态" />
      <el-table-column prop="completeTime" label="任务完成时间" />
      <el-table-column prop="isCancel" label="任务是否取消" />
      <el-table-column fixed="right" label="操作">
        <template #default>
          <el-button size="small"> 查看 </el-button>
          <el-button size="small" type="primary" @click="dialogVisible2 = true">
            分配
          </el-button>
          <el-button size="small" type="danger"> 修改 </el-button>
          <el-button size="small" type="success"> 取消 </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 添加窗口 -->
    <el-dialog
      v-model="dialogVisible"
      title="添加杆塔"
      width="500"
      align-center
    >
      <el-form label-width="auto" :model="[]" style="width: 400px">
        <el-form-item label="杆塔编号">
          <el-input />
        </el-form-item>
        <el-form-item label="所属路线">
          <el-input />
        </el-form-item>
        <el-form-item label="启用状态">
          <el-radio-group v-model="search">
            <el-radio border value="Sponsor">启用</el-radio>
            <el-radio border value="Venue">不启用</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="dialogVisible = false">
            确认
          </el-button>
          <el-button type="primary" @click="dialogVisible = false">
            取消
          </el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 分配窗口 -->
    <el-dialog
      v-model="dialogVisible2"
      title="分配任务"
      align-center
      style="width: fit-content"
    >
      <el-transfer
        v-model="value"
        :data="data"
        :titles="['待选巡检员', '已选巡检员']"
      />
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="dialogVisible2 = false">
            保存
          </el-button>
          <el-button type="primary" @click="dialogVisible2 = false">
            返回
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";

const search = ref("");
const dialogVisible = ref(false);
const dialogVisible2 = ref(false);

const tableData = ref([
  {
    id: "RW0245",
    task: "西渭一线任务巡检",
    route: "西渭一线",
    start: "XW00001",
    end: "XW00256",
    name: "线路管理员测试用户01",
    time: "2013/12/12",
    state: 0,
    completeTime: "2013/12/12",
    isCancel: false,
  },
  {
    id: "RW0245",
    task: "西渭一线任务巡检",
    route: "西渭一线",
    start: "XW00001",
    end: "XW00256",
    name: "线路管理员测试用户01",
    time: "2013/12/12",
    state: 0,
    completeTime: "2013/12/12",
    isCancel: false,
  },
  {
    id: "RW0245",
    task: "西渭一线任务巡检",
    route: "西渭一线",
    start: "XW00001",
    end: "XW00256",
    name: "线路管理员测试用户01",
    time: "2013/12/12",
    state: 0,
    completeTime: "2013/12/12",
    isCancel: false,
  },
  {
    id: "RW0245",
    task: "西渭一线任务巡检",
    route: "西渭一线",
    start: "XW00001",
    end: "XW00256",
    name: "线路管理员测试用户01",
    time: "2013/12/12",
    state: 0,
    completeTime: "2013/12/12",
    isCancel: false,
  },
]);

interface Option {
  key: number;
  label: string;
}

const generateData = () => {
  const data: Option[] = [];
  for (let i = 1; i <= 9; i++) {
    data.push({
      key: i,
      label: `巡检员测试用户${i}`,
    });
  }
  return data;
};

const data = ref<Option[]>(generateData());
const value = ref([]);
</script>

<style scoped>
.table-box {
  width: fit-content;
  margin: 0 auto;
}

.operation-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.input-box {
  color: #747070;
  font-size: 14px;
}

.input__item {
  width: 250px;
  margin: 10px;
}
</style>
